<?php

namespace App\Http\Controllers\Api\Sanctum;

use Illuminate\Http\Request;
use App\User as UserModel;

// 如果在 extends 后跟父类，必须使用 \App\Http\Controllers\Controller。前导 \ 不能少。
class TestController extends \App\Http\Controllers\Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        //$this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function token($id)
    {
        // return UserModel::find($id);
        // {"id":1,"name":"amen","email":"amen@qq.com","email_verified_at":null,"created_at":"2020-06-30T09:25:38.000000Z","updated_at":"2020-06-30T09:25:38.000000Z"}

        $user = UserModel::find($id);
        $token = $user->createToken("hahah");
        return response()->json([
            'code' => 200,
            'token' => $token->plainTextToken
        ]);
    }
}
